CtgEmpleado = function(){

      return {

           

            save: function(){

                  var errorMessage = "";

                  var ctgEmpleadoForm = Ext.getCmp("ctgEmpleadoForm");

                  Asg.Message.progress("Guardando Informaci\u00F3n...");

                  ctgEmpleadoForm.getForm().submit({

                        url: Asg.constants.CONTEXT_PATH + "/admin/empleado/save",

                        timeout: Asg.constants.TIMEOUT_SECONDS,

                        success: function(form, action){

                        Asg.Message.confirmProcess(action.result.message, function(){

                              if(action.result.success){

                                    if(action.result.data)

                                          Asg.Grid.loadData("ctgEmpleadoGrid", action.result.data)

                              }

                        });

                        }

                  });

            },

            getButtonsConfig: function(){

                  return {

                        add: "ctgEmpleadoAddButton",

                        edit: "ctgEmpleadoEditButton",

                        save: "ctgEmpleadoSaveButton",

                        cancel: "ctgEmpleadoCancelButton"

                  };

            },

            initConfig: function(config){

                  return{

                        items: [

                        {

                              xtype: "grid",

                              id: "ctgEmpleadoGrid",

                              frame: true,

                              margins: "5 5 5 5",

                              height: 250,

                              store: new Ext.data.SimpleStore({

                                    data: config.data || [],

                                    fields: [

                                      "ctgEmpleadoId",

                                    "ctgEmpleadoNombres",

                                                "ctgEmpleadoApellidos",

                                                "sgdUsuarioId",

                                                "sgdUsuarioUsuario",

                                                "ctgOficinaId",

                                                "ctgOficinaNombre",

                                                "ctgEmpleadoFechaIngreso",

                                                "ctgEmpleadoFechaRetiro",

                                                "ctgEmpleadoEstado",

                                                "ctgEmpleadoPuesto",

                                                "ctgCargoEmpleadoId",

                                                "ctgCargoEmpleadoNombre",

                                                "ctgEmpleadoCodigo"

                                ]

                              }),

                              selModel: {

                                    listeners: {

                                          selectionchange: function(selectionModel, records){

                                                if(records && records.length > 0){

                                                      var record =  records[0].data;

                                                      if(record!=null){

                                                            Asg.Utils.setValue("ctgEmpleadoId",record.ctgEmpleadoId);

                                                            Asg.Utils.setValue("ctgEmpleadoCodigo",record.ctgEmpleadoCodigo);

                                                            Asg.Utils.setValue("ctgEmpleadoNombres",record.ctgEmpleadoNombres);

                                                            Asg.Utils.setValue("ctgEmpleadoApellidos",record.ctgEmpleadoApellidos);

                                                            Asg.Utils.setValue("sgdUsuarioId",record.sgdUsuarioId);

                                                            Asg.Utils.setValue("ctgOficina",record.ctgOficinaId);

                                                            Asg.Utils.setValue("ctgEmpleadoFechaIngreso",record.ctgEmpleadoFechaIngreso);

                                                            Asg.Utils.setValue("ctgEmpleadoFechaRetiro",record.ctgEmpleadoFechaRetiro);

                                                            Asg.Utils.setValue("ctgEmpleadoEstado",record.ctgEmpleadoEstado);

                                                            Asg.Utils.setValue("ctgEmpleadoPuesto",record.ctgEmpleadoPuesto);

                                                            Asg.Utils.setValue("ctgCargoEmpleadoId",record.ctgCargoEmpleadoId);

                                                           

                                                            Asg.Form.switchButton(CtgEmpleado.getButtonsConfig(), "rowclick");

                                                Asg.Form.switchForm("ctgEmpleadoForm", "rowclick");

                                                      }

                                                     

                                                }

                                          }

                                    }

                              },

                              columns: [

                                  {header: "Id", dataIndex: "ctgEmpleadoId", width: 50},

                                  {header: "Nombres", dataIndex: "ctgEmpleadoNombres", width: 200},

                                  {header: "Apellidos", dataIndex: "ctgEmpleadoApellidos", width: 200},

                                  {header: "Usuario", dataIndex: "sgdUsuario.sgdUsuarioUsuario", width: 100},

                                  {header: "Oficina", dataIndex: "ctgOficina.ctgOficinaNombre", width: 150}

                          ],

                          bbar: [

                               "->",

                               {

                                 id: "ctgEmpleadoAddButton",

                                 text: "Agregar",

                                 iconCls: Asg.constants.ADD_ICON,

                                 handler: function(){

                                       Asg.Form.switchButton(CtgEmpleado.getButtonsConfig(), "add");

                                       Asg.Form.switchForm("ctgEmpleadoForm", "add");

                                       Asg.Grid.clearSelection("ctgEmpleadoGrid");

                                 }

                               },{

                                 id: "    EditButton",

                                 text: "Editar",

                                 iconCls: Asg.constants.EDIT_ICON,

                                 hidden: true,

                                 handler: function(){

                                       Asg.Form.switchButton(CtgEmpleado.getButtonsConfig(), "edit");

                                       Asg.Form.switchForm("ctgEmpleadoForm", "edit");

                                 }

                               },{

                                 id: "ctgEmpleadoSaveButton",

                                text: "Guardar",

                                 iconCls: Asg.constants.SAVE_ICON,

                                 hidden: true,

                                 handler: CtgEmpleado.save

                               },{

                                 id: "ctgEmpleadoCancelButton",

                                 text: "Canelar",

                                 iconCls: Asg.constants.CANCEL_ICON,

                                 hidden: true,

                                 handler: function(){

                                       Asg.Form.switchButton(CtgEmpleado.getButtonsConfig(), "cancel");

                                       Asg.Form.switchForm("ctgEmpleadoForm", "cancel");

                                       Asg.Grid.clearSelection("ctgEmpleadoGrid");

                                 }

                               }

                         ]

                        },{

                              xtype: "tabpanel",

                              minHeight: 400,

                              margins: "0 5 5 5",

                              deferredRender: false,

                              items: [

                                {

                                    title: "DATOS DE GESTOR",

                                    margin: "5 0 0 0",

                                    autoScroll: true,

                                    items: {

                                          xtype: "form",

                                          id: "ctgEmpleadoForm",

                                          border: false,

                                          height: 450,

                                          layout: {

                                                type: "table",

                                                            columns: 4,

                                                            tableAttrs: {

                                                            style: {width: "520px"},

                                                            align: "center"

                                                            }

                                          },

                                          defaults: Asg.Form.defaults({width: 255, colspan: 2}),

                                          items: [

                                              {xtype: "hidden", id: "ctgEmpleadoId", name:"ctgEmpleadoId", colspan: 4},

                                          {xtype: "label", text: "C\u00F3digo:", cls: "x-form-item", colspan: 4},

                                          {

                                                                  xtype: "textfield",

                                                                  id: "ctgEmpleadoCodigo",

                                                                  name: "ctgEmpleadoCodigo",

                                                                  allowBlank: false,

                                                                  disabled: true,

                                                                  colspan: 4,

                                                                  width: 150

                                                            },

                                          {xtype: "label", text: "Nombres:", cls: "x-form-item", colspan: 2},

                                          {xtype: "label", text: "Apellidos:", cls: "x-form-item", colspan: 2},

                                          {

                                                xtype: "textfield",

                                                id: "ctgEmpleadoNombres",

                                                name: "ctgEmpleadoNombres",

                                                allowBlank: false,

                                                disabled: true,

                                                colspan: 2

                                          },

                                          {

                                                xtype: "textfield",

                                                id: "ctgEmpleadoApellidos",

                                                name: "ctgEmpleadoApellidos",

                                                allowBlank: false,

                                                disabled: true,

                                                colspan: 2

                                          },

                                          {xtype: "label", text: "Usuario:", cls: "x-form-item", colspan: 2},

                                          {xtype: "label", text: "Oficina:", cls: "x-form-item", colspan: 2},

                                          {

                                                xtype: "textfield",

                                                id: "sgdUsuarioId",

                                                name: "ctgEmpleados.sgdUsuario.sgdUsuarioId",

                                                allowBlank: false,

                                                disabled: true,

                                                colspan: 2

                                          },

                                          {

                                              xtype: "combobox",

                                                      id: "ctgOficina",

                                                      name: "ctgEmpleados.ctgOficina.ctgOficinaId",

                                                      colspan: 2,

                                                      allowBlank:false,

                                                      store: new Ext.data.SimpleStore({

                                                            data: Asg.Combo.getAllCtgOficinas(),

                                                            fields: [{name: "ctgOficinaId"},{name: "ctgOficinaNombre"}]

                                                      }),

                                                      valueField: "ctgOficinaId",

                                                      displayField: "ctgOficinaNombre"

                                           },

                                           {xtype: "label", text: "Puesto:", cls: "x-form-item", colspan: 2},

                                           {xtype: "label", text: "Cargo:", cls: "x-form-item", colspan: 2},

                                           {

                                                xtype: "textfield",

                                                id: "ctgEmpleadoPuesto",

                                                name: "ctgEmpleadoPuesto",

                                                allowBlank: false,

                                                disabled: true,

                                                colspan: 2

                                                },

                                                {

                                                    xtype: "combobox",

                                                            id: "ctgCargoEmpleado",

                                                            name: "ctgEmpleados.ctgCargoEmpleado.ctgCatalogoId",

                                                            colspan: 2,

                                                            allowBlank:false,

                                                            listWidth: 500,

                                                            store: new Ext.data.SimpleStore({

                                                                  data: Asg.Combo.getAllCtgCargoEmpleados(),

                                                                  fields: [{name: "ctgCargoEmpleadoId"},{name: "ctgCargoEmpleadoNombre"}]

                                                            }),

                                                            valueField: "ctgCargoEmpleadoId",

                                                            displayField: "ctgCargoEmpleadoNombre"

                                                 },

                                           {xtype: "label", text: "Fecha Ingreso:", cls: "x-form-item", colspan: 2},

                                           {xtype: "label", text: "Fecha Retiro:", cls: "x-form-item", colspan: 2},

                                           {

                                                      xtype: "datefield",

                                                id: "ctgEmpleadoFechaIngreso",

                                                name: "ctgEmpleadoFechaIngreso",

                                                maxValue: new Date(),

                                                width: 100,

                                                submitFormat: "Ymd"

                                           },

                                           {

                                                      xtype: "datefield",

                                                id: "ctgEmpleadoFechaRetiro",

                                                name: "ctgEmpleadoFechaRetiro",

                                                maxValue: new Date(),

                                                width: 100,

                                                submitFormat: "Ymd"

                                           },

                                           {xtype: "label", text: "Estado:", cls: "x-form-item", colspan: 4},

                                           {

                                                xtype: "combobox",

                                                            id: "ctgEmpleadoEstado",

                                                            name: "ctgEmpleadoEstado",

                                                            colspan: 4,

                                                            allowBlank:false,

                                                            listWidth: 500,

                                                            store: new Ext.data.SimpleStore({

                                                                  data: Asg.Combo.activeInactiveArray(),

                                                                  fields: [{name: "id"},{name: "desc"}]

                                                            }),

                                                            width: 125,

                                                            valueField: "id",

                                                            displayField: "desc"

                                           }

                                      ]

                                    }

                                }

                          ]

                        }

                    ]

                  };

            }

      };

}();